package com.bonc.modules.rpt.service.impl;

/**
 * @author jinlong
 * @date 2021/7/5
 */

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonc.datasource.annotation.DataSource;
import com.bonc.factory.PageFactory;
import com.bonc.modules.rpt.dao.NoKnownDetailDao;
import com.bonc.modules.rpt.entity.NoKnownDetailEntity;
import com.bonc.modules.rpt.param.FixParam;
import com.bonc.modules.rpt.service.FixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("noKnownDetail")
@DataSource("data")
public class NoKnownDetailServiceImpl extends ServiceImpl<NoKnownDetailDao, NoKnownDetailEntity> implements FixService {

    @Autowired
    private NoKnownDetailDao noKnownDetailDao;

    @Override
    public String getMaxDate() {
        return noKnownDetailDao.getMaxDate();
    }

    @Override
    public Page queryPage(FixParam fixParam) {

        LambdaQueryWrapper<NoKnownDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotNull(fixParam)) {
            if (ObjectUtil.isNotEmpty(fixParam.getDealDate())) {
                queryWrapper.eq(NoKnownDetailEntity::getDealDate, fixParam.getDealDate());
            }
            if (ObjectUtil.isNotEmpty(fixParam.getCityCode())) {
                queryWrapper.eq(NoKnownDetailEntity::getRegionCode, fixParam.getCityCode());
            }
            if (ObjectUtil.isNotEmpty(fixParam.getCountyCode())) {
                queryWrapper.eq(NoKnownDetailEntity::getCityCode, fixParam.getCountyCode());
            }
            if (ObjectUtil.isNotEmpty(fixParam.getGridCode())) {
                queryWrapper.eq(NoKnownDetailEntity::getGriddingCode, fixParam.getGridCode());
            }
        }
        return this.page(PageFactory.defaultPage(),queryWrapper);
    }

    @Override
    public List queryData(FixParam fixParam) {


        LambdaQueryWrapper<NoKnownDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotNull(fixParam)) {
            if (ObjectUtil.isNotEmpty(fixParam.getDealDate())) {
                queryWrapper.eq(NoKnownDetailEntity::getDealDate, fixParam.getDealDate());
            }
            if (ObjectUtil.isNotEmpty(fixParam.getCityCode())) {
                queryWrapper.eq(NoKnownDetailEntity::getRegionCode, fixParam.getCityCode());
            }
            if (ObjectUtil.isNotEmpty(fixParam.getCountyCode())) {
                queryWrapper.eq(NoKnownDetailEntity::getCityCode, fixParam.getCountyCode());
            }
            if (ObjectUtil.isNotEmpty(fixParam.getGridCode())) {
                queryWrapper.eq(NoKnownDetailEntity::getGriddingCode, fixParam.getGridCode());
            }
        }
        return this.baseMapper.selectList(queryWrapper);
    }
}
